package com.blog.blogservice.api.controller.api;

import com.blog.blogservice.app.service.ArticleService;
import com.blog.blogservice.domain.entity.Article;
import com.blog.blogservice.domain.entity.ArticleSummary;
import com.blog.blogservice.domain.entity.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author guanglin.ma
 * @date 2024-03-07 17:51
 */
@RestController("articleAPiController.v1")
@RequestMapping("/api/articles")
public class ArticleApiController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/list/article")
    public ResponseEntity<List<Article>> articleList(Article article) {
        List<Article> articleList = articleService.articleApiList(article);
        return Results.success(articleList);
    }

    @GetMapping("/list/article-summary")
    public ResponseEntity<ArticleSummary> articleSummary() {
        ArticleSummary articleSummary = articleService.articleSummary();
        return Results.success(articleSummary);
    }

    @GetMapping("/list/article-by-type-code")
    public ResponseEntity<List<Article>> articleByTypeCode(@RequestParam("type") String type,
                                                           @RequestParam("code") String code) {
        List<Article> articleList = articleService.articleByTypeCode(type, code);
        return Results.success(articleList);
    }
}
